Skip to content

Fix -Werror=stringop-truncation build failure in fileutils.c#3348

Closed
AlxCzl wants to merge 1 commit into
RfidResearchGroup:masterfrom
AlxCzl:master
Closed

Fix -Werror=stringop-truncation build failure in fileutils.c#3348
AlxCzl wants to merge 1 commit into
RfidResearchGroup:masterfrom
AlxCzl:master

Conversation

@AlxCzl
Copy link
Copy Markdown
Contributor

@AlxCzl AlxCzl commented Jun 2, 2026

strncat(tmp_fullpath, path, sizeof(tmp_fullpath) - 1) into a zero-initialized buffer triggers -Wstringop-truncation on newer GCC because the copy length equals the buffer size, so GCC flags it as potentially truncating.

Replaced the strncat chain with a single snprintf call, which also fixes a secondary bug on the old line 3041 where the third argument to strncat was strlen(tmp_fullpath) - 1 (which is the current string length, not the remaining buffer space). In practice this means the append could overrun the buffer if path was short and d_name was long enough.

Before:

char tmp_fullpath[1023] = {0};
strncat(tmp_fullpath, path, sizeof(tmp_fullpath) - 1);
tmp_fullpath[1023] = 0x00;
strncat(tmp_fullpath, namelist[i]->d_name, strlen(tmp_fullpath) - 1);

After:

snprintf(tmp_fullpath, sizeof(tmp_fullpath), "%s%s", path, namelist[i]->d_name);

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

You are welcome to add an entry to the CHANGELOG.md as well

@AlxCzl AlxCzl force-pushed the master branch 2 times, most recently from 06925b1 to c29afcb Compare June 2, 2026 14:59
@AlxCzl
Copy link
Copy Markdown
Contributor Author

AlxCzl commented Jun 2, 2026

Wrong source branch, sorry. I will close and re-open another PR to make this cleaner.

@AlxCzl AlxCzl closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant